package defult;

import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class Mail {
	
	String username ="vcp.grp11@gmail.com";
	String password ="labgrp11";
	
	public void sendEmail(String to, String cc, String from, String subject, String text) throws AddressException, MessagingException {
		
			Properties props = new Properties();
			props.put("mail.smtp.auth", "true");
			props.put("mail.smtp.starttls.enable", "true");
			props.put("mail.smtp.host", "smtp.gmail.com");//"smtp.gmail.com"
			props.put("mail.smtp.port", "587");		
			Session emailSession = Session.getInstance(props,new javax.mail.Authenticator() {
			protected PasswordAuthentication getPasswordAuthentication() {			
			return new PasswordAuthentication(username, password);
			}
			  });

			Message emailMessage = new MimeMessage(emailSession);
			emailMessage.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
			//emailMessage.addRecipient(Message.RecipientType.CC, new InternetAddress(cc));
			emailMessage.setFrom(new InternetAddress(from));
			emailMessage.setSubject(subject);
			emailMessage.setText(text);
			emailSession.setDebug(true);
			Transport.send(emailMessage);
	}

}
